package cn.qyl.joha.dao.Impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.qyl.joha.common.PageModel;
import cn.qyl.joha.dao.BaseDao;
import cn.qyl.joha.dao.PicDao;
import cn.qyl.joha.dto.Picturcarousel;
import cn.qyl.joha.mapper.PicMapper;

public class PicDaoImpl extends BaseDao implements PicDao {
	/**
	 * 图片轮播数据访问层接口实现方法
	 */
	
	//图片轮播数据总记录数访问层接口实现方法
	@Override
	public int getCountByPic(Picturcarousel pic) {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		int count = picMapper.getCountByPic(pic);
		
		closeSqlSession();
		
		return count;

	}
	//图片轮播数据分页访问层接口实现方法
	@Override
	public List<Picturcarousel> getPicList(PageModel pageModel) {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		List<Picturcarousel> pics = picMapper.getPicList(pageModel);
		
		closeSqlSession();
		
		return pics;
	}
	
	//新增图片轮播数据访问层接口实现方法
	@Override
	public void addPic(Picturcarousel pic) {

		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		picMapper.addPic(pic);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		
	}
	//删除图片轮播数据访问层接口实现方法
	@Override
	public int delPicById(int pid) {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		int count = picMapper.delPicById(pid);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		return count;
	}

	//批量删除图片轮播数据访问层接口实现方法
	@Override
	public int delPicByPids(int[] pids) {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		int count = picMapper.delPicByPids(pids);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		return count;
	}
	//更新图片轮播数据访问层接口实现方法
	@Override
	public Picturcarousel toPicUpdate(int id) {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		Picturcarousel pic =picMapper.toPicUpdate(id);
		
		closeSqlSession();
		
		return pic;
	}
	
	
	@Override
	public List<Picturcarousel> getPicsList() {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		List<Picturcarousel> pics =picMapper.getPicsList();
		
		closeSqlSession();
		
		return pics;
	}
	@Override
	public int PicUpdate(Picturcarousel pic) {
		
		SqlSession sqlSession = getSqlSession();
		
		PicMapper picMapper = sqlSession.getMapper(PicMapper.class);
		
		int count = picMapper.PicUpdate(pic);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		return count;
		

	}

}
